<template>
	<view class="currentPage">
		<topCard :userInfo='userInfo'></topCard>
		<functionList></functionList>
		<buttonOperation @tapBtn='tapBtn' v-if="userInfo">
			退出登录
		</buttonOperation>
		<view class="share">
			<view class="title">
				邀请好友扫码，加入销售平台。
			</view>
			<view class="shareImg">
				<image :src="shareImgUrl" mode=""></image>
			</view>
			<view class="shareBtn">
				<u-button class="custom-style" text="分享给好友" customStyle="background-color: #00C777;color:#fff"
					@click="shareImg"></u-button>
			</view>
		</view>
		<!-- 占位符 -->
		<view style="height: 100upx;width: 100%;"  v-if="userInfo">
			
		</view>
		<u-modal :show="show" :closeOnClickOverlay="true" :showCancelButton='true' :title="'提示'" @confirm='confirm'
			@cancel='cancel' :content="'是否退出登录？'" confirmColor="#00C777"></u-modal>
	</view>
</template>

<script>
	import functionList from '@/components/my/functionList.vue'
	import topCard from '@/components/my/topCard.vue'
	import buttonOperation from '@/components/common/buttonOperation.vue'
	export default {
		components: {
			functionList,
			topCard,
			buttonOperation
		},
		onShareAppMessage() {
			return {
				title: '苗木超市',
				path: '/pages/index/index',
			}
		},
		onShareTimeline: function() {
			return {
				title: '苗木超市',
				path: '/pages/index/index',
			}
		},
		data() {
			return {
				isLogin: false,
				// userInfo:  {
				// 	avatar:'https://cdn.uviewui.com/uview/album/1.jpg',
				// 	nickname:'波比',
				// 	mobile:"18487301491"
				// },
				userInfo:null,
				show: false,
				shareImgUrl:``
			}
		},
		onShow() {
			let url = getApp().globalData.baseUrl
			url  = url.replace(/api/,'')
			this.shareImgUrl = `/static/my/qrImg.jpg`
			this.shareImgUrl = `${url}/assets/img/share.jpg`
				// this.shareImgUrl = `/static/my/qrImg.jpg`
		},
		onLoad() {
			let userInfo = uni.getStorageSync('userInfo')
			this.userInfo = userInfo
			uni.$on('hasLogin', val => {
				if (val) this.isLogin = true
				let userInfo = uni.getStorageSync('userInfo')
				console.log(userInfo)
				this.userInfo = userInfo
			})
		},
		methods: {
			shareImg(){
			  wx.downloadFile({
			    url: this.shareImgUrl,//分享的图片的链接
			    success: (res) => {
			      wx.showShareImageMenu({
			        path: res.tempFilePath
			      })
			    }
			  })
			},
			tapBtn() {
				this.show = true
			},
			confirm() {
				uni.removeStorageSync('token')
				uni.removeStorageSync('userInfo')
				this.show = false
				this.userInfo = null
			},
			cancel() {
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.currentPage {
		min-height: 100vh;
		background-color: #f5f5f5;
		overflow: hidden;
	}
	.share{
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 40px;
		.title{
			color: #00C777;
			margin: 20rpx;
		}
		.shareImg{
			image{
				height: 100px;
				width: 100px;
			}
		}
		.shareBtn{
			width: 90%;
			    margin-top: 10px;
		}
	}
</style>
